import { Component, Vec3, tween } from "cc";
import { EntityTypeEnum, IVec2, distance } from "../../Common";
import DataManager from "../../Runtime/DataManager";
import { ObjectPoolManager } from "../../Runtime/ObjectPoolManager";

export class ScrollManager extends Component {

    id: number
    init(id: number, position: IVec2) {
        this.id = id
        this.node.setPosition(position.x, position.y)

        const targetPos = DataManager.Ins.state.actors[0].position

        const dis = distance(targetPos, this.node.position)
        const time = dis / 800
        tween(this.node)
            .delay(1)
            .to(time, { position: new Vec3(targetPos.x, targetPos.y) })
            .call(() => {
                ObjectPoolManager.Ins.poolFreeNode(EntityTypeEnum.scroll, this.node)

            })
            .start()
    }


}